package x_yeyue.obj;

import x_yeyue.GameWin;
import x_yeyue.utils.GameUtils;

import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class PlaneObj extends GameObj{
    // 我方飞机的血量
    public static int health = 3;

    public PlaneObj(Image img, int x, int y, double speed) {
        super(img, x, y, speed);
    }

    public PlaneObj(Image img, int width, int height, int x, int y, double speed, GameWin frame) {
        super(img, width, height, x, y, speed, frame);
        this.frame.addMouseMotionListener(new MouseAdapter() {
            @Override
            public void mouseMoved(MouseEvent e) {
                PlaneObj.super.x = e.getX() - 19;
                PlaneObj.super.y = e.getY() - 20;
            }
        });
    }

    public PlaneObj() {
    }

    @Override
    public Rectangle getRec() {
        return super.getRec();
    }

    @Override
    public void paintSelf(Graphics g) {
        super.paintSelf(g);
        for (Enemy1Obj enemy1Obj : GameUtils.enemy1ObjsList) {
            if(this.getRec().intersects(enemy1Obj.getRec())){
                enemy1Obj.x = -100;
                enemy1Obj.y = -100;
                GameUtils.removeList.add(enemy1Obj);
//                GameUtils.removeList.add(this);
                health --;
                if(health == 0){
                    GameWin.state = 3;
                }
            }
        }
        for (BossBullet bossBullet : GameUtils.bossBulletList) {
            if(this.getRec().intersects(bossBullet.getRec())){
                bossBullet.setX(-100);
                bossBullet.setY(-100);
                GameUtils.removeList.add(bossBullet);
//                GameWin.state = 3;
                health --;
                if(health == 0){
                    GameWin.state = 3;
                }
            }
        }
    }
}
